package mybatis.plugins.transaction;

import mybatis.transaction.Transaction;
import spring.datasource.DataSourceUtils;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class SpringManagedTransaction implements Transaction {

    private final DataSource dataSource;

    public SpringManagedTransaction(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    @Override
    public Connection getConnection() throws SQLException {
        return DataSourceUtils.getConnection(dataSource);
    }

    @Override
    public void commit() throws SQLException {
        // 由外部框架托管，此处不做实现。
    }

    @Override
    public void rollback() throws SQLException {
        // 由外部框架托管，此处不做实现。
    }

    @Override
    public void close() {
        // 由外部框架托管，此处不做实现。
    }

}
